<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>Edit Raw Material Purchasing Order | Merlion's ERP System</title>
    </ui:define>
    
    <ui:define name="content">
        <f:view beforePhase="#{addMaterialOrder.initView}">
            <h:form prependId="false">
                <p:panel id="panel" header="Add Raw Material Purchasing Order From Material Request List">
                    <p:ajaxStatus style="width:16px;height:16px;">
                        <f:facet name="start">
                            <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                        </f:facet>

                        <f:facet name="complete">
                            <h:outputText value=""/>
                        </f:facet>
                    </p:ajaxStatus>
                    
                    <p:messages  id="messages"/>
                    
                    <p:spacer height="15"/>
                    <p:fieldset legend="Request Material List">
                        <p:dataTable var="materialRequestTemp" value="#{addMaterialOrder.materialRequestToProcess}"
                                     paginator="true" id ="materialRequestTable" 
                                     selection="#{addMaterialOrder.selectedMaterialRequest}">
                             
                            <p:column selectionMode="single" />
                            
                            <p:column sortBy="#{materialRequestTemp.materialRequestTempId}">
                                <f:facet name="header">
                                    <h:outputText value="ID"/>
                                </f:facet>
                                <h:outputText value="#{materialRequestTemp.materialRequestTempId}"/>
                            </p:column>
                            
                            <p:column sortBy="#{materialRequestTemp.materialRequest.materialRequestId}">
                                <f:facet name="header">
                                    <h:outputText value="Material Request ID"/>
                                </f:facet>
                                <h:outputText value="#{materialRequestTemp.materialRequest.materialRequestId}"/>
                            </p:column>                            

                            <p:column sortBy="#{materialRequestTemp.currentDate}">
                                <f:facet name="header">
                                    <h:outputText value="Date"/>
                                </f:facet>
                                <h:outputText value="#{materialRequestTemp.currentDate}"/>
                            </p:column>  
                            
                            <f:facet name="footer">
                                <p:commandButton ajax="true" value ="Display" image="ui-icon ui-icon-search"                                                
                                                 update="display1 mrMaterialLineTable"/>
                            </f:facet>
                        </p:dataTable>
                    </p:fieldset>
                    
                    <p:spacer height="20"/> 
 
                    <p:fieldset legend="Display Selected Material Request">
                            <h:panelGrid id="display1" columns="2" cellpadding="4" >
                                <h:outputText value="Material Request ID: "/>
                                <h:outputText value="#{addMaterialOrder.selectedMaterialRequest.materialRequestTempId}"/>

                                <h:outputText value="Date: "/>
                                <h:outputText value="#{addMaterialOrder.selectedMaterialRequest.currentDate}"/>                                    
                            </h:panelGrid>

                        <p:dataTable var="materialLine" value="#{addMaterialOrder.selectedMaterialRequest.materialLines}"
                                         dynamic="true" paginator="true" selection="#{addMaterialOrder.selectedMaterialLines}" id ="mrMaterialLineTable">

                                <f:facet name="header">
                                    Raw Material Need To Buy
                                </f:facet>

                                <p:column selectionMode="multiple"/>

                                <p:column headerText="ID">
                                    <h:outputText value="#{materialLine.materialLineId}"/>
                                </p:column>

                                <p:column headerText="Raw Material Type">
                                    <h:outputText value="#{materialLine.rawMaterial.materialType}"/>
                                </p:column>

                                <p:column headerText="Quantity">
                                    <h:outputText value="#{materialLine.quantity}"/>
                                </p:column>
                                
                                <p:column headerText="LotQuantity">
                                    <h:outputText value="#{materialLine.lotQuantity}"/>
                                </p:column>

                                <f:facet name="footer">
                                    <p:commandButton value="Add Selected Raw Material Lines" update ="warning messages panel displayMulti display3 "
                                                     oncomplete ="createMaterialOrderDialog.show()" />
                                </f:facet>
                            </p:dataTable>
 
                    </p:fieldset>
                </p:panel>    
             </h:form>    
             
            <h:form prependId="false">
                    <p:dialog header="Create Material Purchasing Order" widgetVar="createMaterialOrderDialog" 
                              width="700" height="550" resizable="true" showEffect="clip" hideEffect="fold">
                        
                        <h:panelGrid columns="2" id ="display3">
                            <h:outputText value ="Select Suppliers: "/>
                            <h:selectOneMenu id="suppliers" value="#{addMaterialOrder.selectedSupplier}">
                                <f:selectItem itemLabel="Suppliers" itemValue=""/>
                                <f:selectItems value="#{addMaterialOrder.suppliers}"/>
                            </h:selectOneMenu>
                        </h:panelGrid>
                        
                        <h:outputText value="Materials Need To Buy:"/>
                        <p:spacer height="15"/> 
                        
                        <p:dataTable var="materialLine" value="#{addMaterialOrder.materialLineList}"
                                         dynamic="true" paginator="true" id ="displayMulti">
                            <p:column headerText="Raw Material Type">
                                <h:outputText value="#{materialLine.rawMaterial.materialType}"/>
                            </p:column>

                            <p:column headerText="Quantity">
                                <h:outputText value="#{materialLine.quantity}"/>
                            </p:column>
                            
                            <p:column headerText ="Lot Quantity">
                                <h:outputText value ="#{materialLine.lotQuantity}"/>
                            </p:column>
                        </p:dataTable>
                        
                        <p:spacer height="10"/> 
                        <p:messages id="warning"/>

                        <p:commandButton id="btn" value="Create Raw Material Purchasing Order"  
                                         actionListener="#{addMaterialOrder.createMaterialOrder}" oncomplete="createMaterialOrderDialog.hide()" 
                                         ajax="true" update="messages panel mrMaterialLineTable materialRequestTable " />
                        <p:commandButton value="Cancel" onclick="createMaterialOrderDialog.hide()" type="button"/>
                    </p:dialog>                    
              </h:form>
        </f:view>
    </ui:define>

</ui:composition>
